////////////////////////////////////////////////////////////////////////////
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//  Portions Copyright (c) Kentaro Sekimoto All rights reserved.
//
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>
#include "..\..\..\DeviceCode\Targets\Native\RX62N\DeviceCode\iodefine.h"

#ifdef __cplusplus
extern "C" {
#endif
void BootstrapCode_Ext_SRAM(void)  __attribute__((section("SectionForBootstrapOperations")));
void BootstrapCode_Board(void)  __attribute__((section("SectionForBootstrapOperations")));
#ifdef __cplusplus
}
#endif

void BootstrapCode_Ext_SRAM(void) __attribute__((section("SectionForBootstrapOperations")));
void BootstrapCode_Ext_SRAM(void)
{
    //SYSTEM.SCKCR.LONG = 0x00010100;    // ICLK=96MHz,BCLK=48MHz,PCLK=48MHz
    IOPORT.PF0CSE.BIT.CS4E = 1;
    IOPORT.PF1CSS.BIT.CS4S = 0;
    IOPORT.PF3BUS.BYTE = 0x1f;
    IOPORT.PF4BUS.BYTE = 0xff;
    IOPORT.PF5BUS.BYTE = 0x52;
    IOPORT.PF6BUS.BYTE = 0x00;
    BSC.CS4MOD.WORD = 0x8001;
    BSC.CS4CR.WORD = 0x0001;
    SYSTEM.SYSCR0.WORD = 0x5a03;
    BSC.CS4WCR1.LONG = 0x04040000;
    BSC.CS4WCR2.LONG = 0x00110111;
    BSC.CS4REC.WORD = 0x0000;
}

void BootstrapCode_Board(void) __attribute__ ((section ("SectionForBootstrapOperations")));
void BootstrapCode_Board(void)
{
    BootstrapCode_Ext_SRAM();
}
